<meta charset="utf-8" />
<div class="breadcrumbs" id="breadcrumbs">
	<ul class="breadcrumb">
		<li><i class="ace-icon fa fa-home home-icon"></i> <a href="index">主页</a>
		</li>

		<li><span>控制台</span></li>
	</ul>
	<!-- /.breadcrumb -->
</div>
<div class="page-content">


	<div class="row">
		<div class="col-xs-12">

			<div class="clearfix"></div>
			<div class="table-header">用户管理</div>

			<!-- div.table-responsive -->

			<!-- div.dataTables_borderWrap -->
			<div>
				<div id="dynamic-table_wrapper"
					class="dataTables_wrapper form-inline no-footer">
					<form method="post" action="users/allUser" id="main">
						<div class="row">
							<div class="col-xs-8">
								用户名:<input type="text" placeholder="用户名" class="form-control" name="username" />
								姓名:<input type="text" placeholder="姓名" class="form-control" name="name" /> 
								职位:<input type="text" placeholder="职位" class="form-control" name="position" />
								
								<a class="btn btn-sm btn-primary" id="submi">查询</a>
								<input type="reset" class="btn btn-sm btn-primary" onclick="javascript:chongZhi()" value="重置">
							</div>
							<div class="pull-right">
								<a class="btn btn-sm btn-primary"
									href="javascript:addUser()">添加用户</a>
							</div>
						</div>
					</form>
					<script type="text/javascript" src="js/laypage.js"></script>
					<script type="text/javascript">
//重置查询
function chongZhi(){
	var a = "";
	$.post("users/allUser",{"name":a},function(){
		pageChange(1);
	});
}


					/* 填充表格 */
function trList(data) {
	
	var dataStr = "";
	$.each(data, function(i, a) {
	
	        $.each(a.users.list, function(i, v) {//遍历users
	            //alert(v.id);  //弹出对话框
	            dataStr += '<tr role="row" class="even">';
	            dataStr += '<td>'+v.username+'</td>';
	            dataStr += '<td>'+v.name+'</td>';
	            dataStr += '<td>';
	        	$.each(a.depts, function(i, m) {//遍历depts
	            	if(m.dept_id==v.dept_id) dataStr += m.dept_name;
	        	}); 
	            
	            dataStr +='</td>';
	            dataStr += '<td>'+v.position+'</td>';
	            dataStr += '<td>';
	        	$.each(a.roles, function(i, m) {//遍历roles
	            	if(m.role_id==v.role_id) dataStr += m.role_name;
	        	}); 
	        
	            
	            dataStr +='</td>';
	            dataStr +='<td class="hidden-480">';
	            if(v.status==true){
	            	
	            	dataStr += '<span class="label label-sm label-success">';
	            	dataStr +='在职';
	            	dataStr +='</span>';
	            	
	            }else{
	            	dataStr += '<span class="label label-sm label-inverse arrowed-in">离职</span>';
	            }
	            dataStr +='</td>';
	            dataStr += '<td><div class="hidden-sm hidden-xs action-buttons"><a href="';
	            dataStr +='javascript:allInf('+v.id+',\''+v.username+'\',\''+v.name+'\',\''+v.gender+'\','+v.age+',\'';
	            if(v.dept_id==null){
	            	dataStr += '无';
	            }else{
	            $.each(a.depts, function(i, m) {//遍历depts
	            if(m.dept_id==v.dept_id) dataStr += m.dept_name;
	        		});
	        	}
	            dataStr +='\',\''+v.position+'\',\''+v.education+'\',\''+v.hiredate+'\','+v.seniority+',\''+v.email+'\',\''+v.regist_date+'\',\'';
	            if(v.role==null){
	            	dataStr += '无';
	            }else{
	            $.each(a.roles, function(i, m) {//遍历roles
	            	if(m.role_id==v.role_id) dataStr += m.role_name;
	        	});}
	            
	            dataStr +='\',\'';
	            if(v.status==true){
	            	dataStr +='在职';
	            }else{
	            	dataStr += '离职';
	            }
	            dataStr +='\')" class="blue"> <i class="ace-icon fa fa-search-plus bigger-130"></i> </a> ';
	    		dataStr += '<a href="javascript:updateUser('+v.id+',\''+v.username+'\',\''+v.name+'\',\''+v.position+'\',\''+v.email+'\',\''+v.hiredate+'\',\''+v.education+'\','+v.age+',\''+v.gender+'\')"';
				dataStr += ' class="green "><i class="ace-icon fa fa-pencil bigger-130"></i> </a> <a href="javascript:deleteU('+v.id+')" class="red"> <i class="ace-icon fa fa-trash-o bigger-130"></i> </a></div> </td></tr>';
	        });
	    
	});
	// 把拼接好的表格内容填充到指定位置
	$("#tbody").html(dataStr);

}

					
					
					
					
			$("#submi").click(function(){
					$.post("users/allUser",$("#main").serialize(),function(data){
					pageChange(1);
					});
					});

function trPost(data){
			if(data.totalPage!=1){
				$("#laypage_3").addClass("hide");
				$("#get_pagination3").removeClass("hide");
				laypage({
				cont : $('#get_pagination3'), //容器。值支持id名、原生dom对象，jquery对象,
				pages : data.totalPage, //总页数
				skip : true, //是否开启跳页
				skin : '#2283C5',//保持ace中间的样式
				first: 1,
				last : data.totalPage, //总页数，将尾页显示为总页数
				curr : data.pageNumber,//当前页
				groups : 5, //连续显示分页数
				jump : function(obj, first) {
					if (!first) { //一定要加此判断，否则初始时会无限刷新
						pageChange(obj.curr);
					}
					}
				});
			}else{
				$("#get_pagination3").addClass("hide");
				$("#laypage_3").removeClass("hide");
			}
			
			
	}





function pageChange(curr) {
	$.get("users/allUser", {"pageNumber": curr}, function(data) {
		trList(data); //调用上面trList()方法，填充表格数据
		trPost(data[0].users);
		laypage({
		    cont: $('#pages'), //容器。值支持id名、原生dom对象，jquery对象,
		    pages: data[0].users.totalPage, //总页数
		    skip: true, //是否开启跳页
		    skin: 'molv',//设置信息流模式样式
		    last:  data[0].users.totalPage, //总页数，将尾页显示为总页数
		    curr: data[0].users.pageNumber,//当前页
		    groups: 3, //连续显示分页数
		    jump: function(obj, first) {
			if(!first){ //一定要加此判断，否则初始时会无限刷新
				pageChange(obj.curr);
			}
			
			
		    }
		});
		
		
	});
}



function deleteU(id){
	
	layer.confirm('是否确定删除此用户？', {btn : [ '确定', '取消' ]}, function() {
		$.post("users/delete",{"id":id}, function() {
			layer.msg("已删除");
			pageChange(1);
		});
	}, function() {
		layer.msg("已取消");
	});
}


pageChange(1);


</script>
<!-- 更改每页显示数据的数目 -->
<script type="text/javascript">
	var sel=document.getElementById("sel");
sel.onchange=function(){
/* alert(sel.options[sel.selectedIndex].value); */
		$.post("users/fanye", {"infNumber" :sel.options[sel.selectedIndex].value}, function(data) {
			pageChange(1);							
		});
}
</script>
					<table
						class="table table-striped table-bordered table-hover">
						<thead>
							<tr>
								<th>用户名</th>
								<th>姓名</th>
								<th>所属部门</th>
								<th>职位</th>
								<th>角色</th>
								<th rowspan="1" colspan="1">状态</th>
								<th width="120">操作</th>
								


							</tr>
						</thead>
						<tbody id="tbody">

						</tbody>

					</table>

					<div class="row">
						<div class="col-xs-12">

							<div class="dataTables_paginate paging_simple_numbers  pull-left">
								<label>显示<select name="dynamic-table_length"
									aria-controls="dynamic-table" class="form-control input-sm"  id="sel">
									    <option value="10">10</option>
										<option value="20">20</option>
										<option value="50">50</option>
										<option value="100">100</option>
								</select> 条记录</label>
								</div>
								<div class="dataTables_paginate paging_simple_numbers">
										<ul class="pagination" id="get_pagination3">
										</ul>
										<div class="laypage_main laypageskin_molv" id="laypage_3">
											<span class="laypage_curr" style="background-color:#2283C5">1</span><span
												class="laypage_total"><label>到第</label><input max="1"
												min="1" class="laypage_skip" type="number"><label>页</label>
												<button type="button" class="laypage_btn">
													确定
													</button>
											</span>
										</div>
									</div>

						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<!-- 更新用户 -->
<div class="hidden" id="up">
	<div class="col-xs-1"></div>
	<div class="col-xs-9">
		<form id="uup" method="post">
			<input type="hidden" name="role.role_id">
			<div class="form-group">
				<label class="col-sm-4 control-label no-padding-right"
					for="form-field-1">原用户编号</label>
				<div class="col-sm-8" style="float: left">
					<input type="text" class="form-control" name="id" id="user_id"
						value='' />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-4 control-label no-padding-right"
					for="form-field-1">用户名</label>
				<div class="col-sm-8" style="float: left">
					<input type="text" class="form-control" name="username"
						id="user_username" value="" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-4 control-label no-padding-right"
					for="form-field-1">姓名</label>
				<div class="col-sm-8" style="float: left">
					<input type="text" class="form-control" name="name" id="user_name"
						value="" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-4 control-label no-padding-right"
					for="form-field-1">性别</label>
				<div>
					&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="gender" value="男" id="男" />男 
					<input type="radio" name="gender" value="女" id="_nv"/>女
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-4 control-label no-padding-right"
					for="form-field-1">年龄</label>
				<div class="col-sm-8">
					<select name="age"> <#list 16..65 as n>
						<option value="${n}" id="age${n}">${n}</option> </#list>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-4 control-label no-padding-right"
					for="form-field-1" color="red">部门与角色</label>
				<div class="col-sm-8">
					<select name="dept_id" id="areaid"
						onChange="setTown('areaid','townid')">
						<option value="">请选部门</option> <#list depts as d>
						<option value="${d.dept_id!}">${d.dept_name!}</option> </#list>
					</select> <select name="role_id" id="townid">
						<option value="">请选角色</option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-4 control-label no-padding-right"
					for="form-field-1">职位</label>
				<div class="col-sm-8" style="float: left">
					<input type="text" class="form-control" name="position"
						id="user_position" value="" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-4 control-label no-padding-right"
					for="form-field-1">学历</label>
				<div class="col-sm-8">
					<select name="education" id="education_">
						<option value="初中" id="cz">初中</option>
						<option value="高中" id="gz">高中</option>
						<option value="专科" id="zk">专科</option>
						<option value="本科" id="bk">本科</option>
						<option value="硕士" id="ss">硕士</option>
						<option value="博士" id="bs">博士</option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-4 control-label no-padding-right"
					for="form-field-1">参加工作日期</label>
				<div class="col-sm-8" style="float: left">
					<input type="text" class="form-control" name="hiredate"
						id="user_hiredate" onClick="WdatePicker()" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-4 control-label no-padding-right"
					for="form-field-1">邮箱地址</label>
				<div class="col-sm-8" style="float: left">
					<input type="text" class="form-control" name="email"
						id="user_email" value="" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-4 control-label no-padding-right"
					for="form-field-1">状态</label>
				<div class="col-sm-8">
					<input type="radio" name="status" value="1" checked />在职&nbsp;&nbsp;&nbsp;
					<input type="radio" name="status" value="0" />离职
				</div>
			</div>


		</form>
	</div>
	<div class="col-xs-2"></div>
</div>

<!-- 添加用户 -->
<div class="hide" id="add">
	<div class="col-xs-1"></div>
	<div class="col-xs-9">
		<form id="pform" method="post">
			<!-- <input type="hidden" name="role.role_id"> -->

			<div class="form-group">
				<label class="col-sm-4 control-label no-padding-right"
					for="form-field-1">用户名</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" name="u.username" id="addusername"
						value="" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-4 control-label no-padding-right"
					for="form-field-1">密码</label>
				<div class="col-sm-8">
					<input type="password" class="form-control" name="u.password"
						id="addpassword" value="" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-4 control-label no-padding-right"
					for="form-field-1">姓名</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" name="u.name" id="addname"
						value="" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-4 control-label no-padding-right"
					for="form-field-1">性别</label>
				<div>
					&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="u.gender"
						value="男" checked />男 <input type="radio" name="u.gender"
						value="女" />女
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-4 control-label no-padding-right"
					for="form-field-1">年龄</label>
				<div class="col-sm-8">
					<select name="u.age"> <#list 16..65 as n>
						<option value="${n}">${n}</option> </#list>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-4 control-label no-padding-right"
					for="form-field-1">部门与角色</label>
				<div class="col-sm-8">
					<select name="u.dept_id" id="areaid1"
						onChange="setTown('areaid1','townid1')">
						<option value="">请选部门</option> <#list depts as d>
						<option value="${d.dept_id!}">${d.dept_name!}</option> </#list>
					</select> <select name="role_id" id="townid1">
						<option value="">请选角色</option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-4 control-label no-padding-right"
					for="form-field-1">职位</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" name="u.position" id="addposition"
						value="" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-4 control-label no-padding-right"
					for="form-field-1">学历</label>
				<div class="col-sm-8">
					<select name="u.education">
						<option value="初中">初中</option>
						<option value="高中">高中</option>
						<option value="专科">专科</option>
						<option value="本科">本科</option>
						<option value="硕士">硕士</option>
						<option value="博士">博士</option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-4 control-label no-padding-right"
					for="form-field-1">参加工作日期</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" name="u.hiredate" id="addhiredate"
						onClick="WdatePicker()" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-4 control-label no-padding-right"
					for="form-field-1">邮箱地址</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" name="u.email" id="addemail"
						value="" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-4 control-label no-padding-right"
					for="form-field-1">状态</label>
				<div class="col-sm-8">
					<input type="radio" name="u.status" value="1" checked />在职&nbsp;&nbsp;&nbsp;
					<input type="radio" name="u.status" value="0" />离职
				</div>
			</div>


		</form>
	</div>
	<div class="col-xs-2"></div>
</div>
<!-- 显示用户信息 -->
<div class="hide" id="sh">
	<div class="col-xs-2"></div>
	<div class="col-xs-8">
		<form id="show" method="post">
			<!-- <input type="hidden" name="role.role_id"> -->




			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right"
					for="form-field-1">用户编号</label>
				<div class="col-sm-9">
					<input class="form-control" id="user_id1" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right"
					for="form-field-1">用户名</label>
				<div class="col-sm-9">
					<input class="form-control" id="user_username1" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right"
					for="form-field-1">姓名</label>
				<div class="col-sm-9">
					<input class="form-control" id="user_name1" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right"
					for="form-field-1">性别</label>
				<div class="col-sm-9">
					<input class="form-control" id="user_gender1" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right"
					for="form-field-1">年龄</label>
				<div class="col-sm-9">
					<input class="form-control" id="user_age1" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right"
					for="form-field-1">部门</label>
				<div class="col-sm-9">
					<input class="form-control" id="user_dept1" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right"
					for="form-field-1">职位</label>
				<div class="col-sm-9">
					<input class="form-control" id="user_position1" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right"
					for="form-field-1">学历</label>
				<div class="col-sm-9">
					<input class="form-control" id="user_education1" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right"
					for="form-field-1">工作日期</label>
				<div class="col-sm-9">
					<input class="form-control" id="user_hiredate1" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right"
					for="form-field-1">工龄</label>
				<div class="col-sm-9">
					<input class="form-control" id="user_seniority1" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right"
					for="form-field-1">注册日期</label>
				<div class="col-sm-9">
					<input class="form-control" id="user_regist_date1" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right"
					for="form-field-1">邮箱地址</label>
				<div class="col-sm-9">
					<input class="form-control" id="user_email1" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right"
					for="form-field-1">角色</label>
				<div class="col-sm-9">
					<input class="form-control" id="user_role1" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right"
					for="form-field-1">状态</label>
				<div class="col-sm-9">
					<input class="form-control" id="user_status1" />
				</div>
			</div>




		</form>
	</div>
	<div class="col-xs-2"></div>
</div>
<!-- 显示用户信息 -->
<script type="text/javascript">
	function allInf(id,username,name,gender,age,dept,position,education,hiredate,seniority,email,regist_date,role,status) {
		document.getElementById("show").reset();
		$("#user_id1").val(id);
		$("#user_username1").val(username);
		$("#user_name1").val(name);
		$("#user_gender1").val(gender);
		$("#user_age1").val(age);
		$("#user_dept1").val(dept);
		$("#user_position1").val(position);
		$("#user_education1").val(education);
		$("#user_hiredate1").val(hiredate);
		$("#user_seniority1").val(seniority);
		$("#user_email1").val(email);
		$("#user_regist_date1").val(regist_date);
		$("#user_role1").val(role);
		$("#user_status1").val(status);
		$('#sh').removeClass("hide");
		userModel = layer.open({
			type : 1,
			shade : [ 0.5 ],
			title : '角色详细信息', //不显示标题
			area : [ '40%', '80%' ], //显示空间
			content : $('#sh'), //捕获的元素
			btn : [  '关闭' ],
			yes : function(index, layero) { //或者使用btn1
				$.post("sh", $("#show").serialize(), function(data) {

					layer.close(index);
					$('#sh').addClass("hide");
					//document.getElementById("show").submit();
				});
			},
			cancel : function(index) {
				layer.close(index);
				$('#sh').addClass("hide"); //取消继续隐藏
			},
		});
	};
</script>
<!-- 添加用户 -->
<script type="text/javascript">
	function addUser() {
		document.getElementById("pform").reset();
		$('#add').removeClass("hide");
		userModel = layer.open({
			type : 1,
			shade : [ 0.5 ],
			title : '角色添加', //不显示标题
			area : [ '40%', '80%' ], //显示空间
			content : $('#add'), //捕获的元素
			btn : [ '添加', '取消' ],
			yes : function(index, layero) { //或者使用btn1
				var username = document.getElementById("addusername").value;
				var password = document.getElementById("addpassword").value;
				var name = document.getElementById("addname").value;
				var dept = document.getElementById("areaid1").value;
				var role = document.getElementById("townid1").value;
				var position = document.getElementById("addposition").value;
				var hiredate = document.getElementById("addhiredate").value;
				var email = document.getElementById("addemail").value;
				
				if(username==""){
					errorMsg("用户名不能为空");
					return false;
				}
				if (escape(username).indexOf("%u") != -1){
					errorMsg("用户名不能包含汉字");
					return false;
				}
				if(password==""){
					errorMsg("密码不能为空");
					return false;
				}
				if(name==""){
					errorMsg("姓名不能为空");
					return false;
				}
				if(dept==""){
					errorMsg("部门需要手动选择");
					return false;
				}
				if(role==""){
					errorMsg("角色需要手动选择");
					return false;
				}
				if(position==""){
					errorMsg("职位不能为空");
					return false;
				}
				if(hiredate==""){
					errorMsg("参加工作日期不能为空");
					return false;
				}
				if(email==""){
					errorMsg("电子邮箱不能为空");
					return false;
				}
				var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
				if(!myreg.test(email)){
					errorMsg("请输入正确的邮箱格式");
					return false;
				}
				$.post("users/addUser", $("#pform").serialize(), function(data) {
					if(data=="fail"){
						errorMsg("该用户名已存在，请重新输入");
						//return false;
					}else{
						layer.close(index);
						$('#add').addClass("hide");
						pageChange(1);
						layer.msg("添加成功");
					}
					//document.getElementById("pform").submit();
				});
			},
			cancel : function(index) {
				layer.close(index);
				$('#add').addClass("hide"); //取消继续隐藏
				layer.msg("已取消");
			},
		});
	};
</script>
<!-- 更新用户 -->
<script type="text/javascript">
	function updateUser(id,uname,name,position,email,hiredate,education,age,gender) {
		document.getElementById("uup").reset();
		$("#user_id").val(id);
		$("#user_username").val(uname);
		$("#user_name").val(name);
		$("#user_position").val(position);
		$("#user_email").val(email);
		$("#user_hiredate").val(hiredate);
		var age_ = document.getElementById("age"+age);
		age_.selected = 'selected';
		var edu = document.getElementById("cz");;
		if(education=='高中') edu = document.getElementById("gz");
		else if(education=='专科') edu = document.getElementById("zk");
		else if(education=='本科') edu = document.getElementById("bk");
		else if(education=='硕士') edu = document.getElementById("ss");
		else if(education=='博士') edu = document.getElementById("bs");
		edu.selected = 'selected';
		if(gender=='男'){
			var sex1 = document.getElementById("男");
			sex1.setAttribute("checked", "checked");
		}
		if(gender=='女'){
			var sex2 = document.getElementById("_nv");
			sex2.setAttribute("checked", "checked");
		}
		$('#up').removeClass("hidden");
		userModel = layer.open({
			type : 1,
			shade : [ 0.5 ],
			title : '角色更新', //不显示标题
			area : [ '40%', '60%' ], //显示空间
			content : $('#up'), //捕获的元素
			btn : [ '更新', '取消' ],
			yes : function(index, layero) { //或者使用btn1
				var username = document.getElementById("user_username").value;
				var name = document.getElementById("user_name").value;
				var dept = document.getElementById("areaid").value;
				var role = document.getElementById("townid").value;
				var position = document.getElementById("user_position").value;
				var hiredate = document.getElementById("user_hiredate").value;
				var email = document.getElementById("user_email").value;
				errorMsg(role);
				if(username==""){
					errorMsg("用户名不能为空");
					return false;
				}
				if(name==""){
					errorMsg("姓名不能为空");
					return false;
				}
				if(dept==""){
					errorMsg("部门需要手动选择");
					return false;
				}
				 if(role==""){
					errorMsg("角色需要手动选择");
					return false;
				} 
				if(position==""){
					errorMsg("职位不能为空");
					return false;
				}
				if(hiredate==""){
					errorMsg("参加工作日期不能为空");
					return false;
				}
				if(email==""){
					errorMsg("电子邮箱不能为空");
					return false;
				}
				var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
				if(!myreg.test(email)){
					errorMsg("请输入正确的邮箱格式");
					return false;
				}
				
				$.post("users/update", $("#uup").serialize(), function(data) {
					if(data=="fail"){
						errorMsg("该用户名已存在，请重新输入");
						//return false;
					}else{
						layer.close(index);
						$('#up').addClass("hidden");
						pageChange(1);
						layer.msg("修改成功");
					}
					
					
					//document.getElementById("uup").submit();
				});
			},
			cancel : function(index) {
				layer.close(index);
				$('#up').addClass("hidden"); //取消继续隐藏
				layer.msg("已取消");
			},
		});
	};
</script>


<script type="text/javascript">

	var areaArray = new Array();
	<#list depts as d>
	areaArray[areaArray.length] = new Array("${d.dept_id!}", "${d.dept_name!}");
	</#list>
	var townArray = new Array();
	<#list roles as r>
	townArray[townArray.length] = new Array("${r.dept_id!}", "${r.role_name!}",
			"${r.role_name!}");
	</#list>
	function setTown(obj1ID, obj2ID) {
		var objArea = document.getElementById(obj1ID);
		var objTown = document.getElementById(obj2ID);
		var i;
		var itemArray = null;
		if (objArea.value.length > 0) {
			itemArray = new Array();
			for (i = 0; i < townArray.length; i++) {
				if (townArray[i][0] == objArea.value) {
					itemArray[itemArray.length] = new Array(townArray[i][1],
							townArray[i][2]);
				}
			}
		}
		for (i = objTown.options.length; i >= 0; i--) {
			objTown.options[i] = null;
		}
		objTown.options[0] = new Option("请选角色");
		objTown.options[0].value = "";

		if (itemArray != null) {
			for (i = 0; i < itemArray.length; i++) {
				objTown.options[i + 1] = new Option(itemArray[i][1]);
				if (itemArray[i][0] != null) {
					objTown.options[i+1].value = itemArray[i][0];
				}
			}
		}
	}
	function errorMsg(errorInfo) {
		layer.confirm(errorInfo, {
			title: '提示信息',
			btn : [ '确定' ]
		//按钮
		}, function(index) {
			layer.close(index);
		});
	}
</script>